import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import {
  IsEnum,
  IsISO8601,
  IsNotEmpty,
  IsOptional,
  IsString,
  IsUUID,
  MaxLength,
} from 'class-validator';
import { TaskStatus, TaskType } from '../../common/enums';

export class CreateTaskDto {
  @ApiProperty({
    description: 'Task title',
    maxLength: 128,
    example: 'Create monthly report',
  })
  @IsString()
  @IsNotEmpty()
  @MaxLength(128)
  title: string;

  @ApiPropertyOptional({
    description: 'Task description',
    example: 'Create a detailed monthly report for the marketing department',
  })
  @IsString()
  @IsOptional()
  description?: string;

  @ApiProperty({
    description: 'Task category ID',
    format: 'uuid',
    example: '123e4567-e89b-12d3-a456-426614174000',
  })
  @IsUUID()
  @IsNotEmpty()
  taskCategoryId: string;

  @ApiProperty({
    description: 'Task type (single or global)',
    enum: TaskType,
    default: TaskType.SINGLE,
    example: TaskType.SINGLE,
  })
  @IsEnum(TaskType)
  type: TaskType = TaskType.SINGLE;

  @ApiPropertyOptional({
    description: 'Parent task ID if this is a subtask',
    format: 'uuid',
    example: '123e4567-e89b-12d3-a456-426614174000',
  })
  @IsUUID()
  @IsOptional()
  parentTaskId?: string;

  @ApiPropertyOptional({
    description:
      'User ID to whom the task is assigned (required for single tasks, optional for global tasks)',
    format: 'uuid',
    example: '123e4567-e89b-12d3-a456-426614174000',
  })
  @IsUUID()
  @IsOptional()
  assignedUserId?: string;

  @ApiPropertyOptional({
    description: 'Task status',
    enum: TaskStatus,
    default: TaskStatus.NOT_START,
    example: TaskStatus.NOT_START,
  })
  @IsEnum(TaskStatus)
  @IsOptional()
  status?: TaskStatus = TaskStatus.NOT_START;

  @ApiPropertyOptional({
    description: 'Task start date and time',
    format: 'date-time',
    example: '2025-01-01T09:00:00Z',
  })
  @IsISO8601()
  @IsOptional()
  startTime?: string;

  @ApiPropertyOptional({
    description: 'Task due date and time',
    format: 'date-time',
    example: '2025-12-31T23:59:59Z',
  })
  @IsISO8601()
  @IsOptional()
  dueTime?: string;

  @ApiPropertyOptional({
    description: 'Task template ID if this task is created from a template',
    format: 'uuid',
    example: '123e4567-e89b-12d3-a456-426614174000',
  })
  @IsUUID()
  @IsOptional()
  taskTemplateId?: string;
}
